import React from 'react'
import { Route, withRouter } from 'react-router-dom'

//1.登陆权限
//2.登陆后的页面权限
const AuthRoute = ({ component: Component, context: Context, ...rest }) => {
	//token存在的表象
	let isLogged = (localStorage.getItem('token') || '').length > 0

	if (!isLogged) {
		//给个提示，延时跳转登陆页
		alert('需要登陆权限,正在跳转登陆页...')
		window.location.href = '/login.html'
	}

	return (
		<>
			<Route
				{...rest}
				render={(props) => {
					return <Component {...props} />
				}}
			/>
		</>
	)
}

export default withRouter(AuthRoute)
